<?php
/**
 * Created by PhpStorm.
 * User: Gustav
 * Date: 2018/7/25
 * Time: 16:28
 */

namespace app\litera\controller;

use app\common\controller\GlobalVariable;
use app\user\model\User;
//use think\captcha\Captcha;
use think\Controller;
use think\Db;


class Litera extends Controller
{

    /**
     * 返回全部期刊
     */

    public function journal()
    {
        $lists = Db::table('xwd_doc_journal')->select();
        $thesis = [];
        foreach ($lists as $list) {
            $can = [];
            $can['journal_id'] = $list['journal_id'];
            $can['url'] = $list['url'];
            $can['url_object_id'] = $list['url_object_id'];
            $can['periodical'] = $list['periodical'];
            $can['impact_factor'] = $list['impact_factor'];
            $can['eigenfactor'] = $list['eigenfactor'];
            $can['article_influence_score'] = $list['article_influence_score'];
            $can['introduce'] = $list['introduce'];
            $can['subjects'] = $list['subjects'];
            array_push($thesis, $can);
        }
        return GlobalVariable::promptData($thesis);
    }

    /**
     * 获得指定id文章
     */

    public function getThesis()
    {
        $thesis_id = input('get.thesis_id');
        $list = Db::table('xwd_doc_thesis')->where('thesis_id', $thesis_id)->select();
        if ($list) {
            $journal_id = $list[0]["journal_id"];
            $list2 = Db::table('xwd_doc_journal')->where('journal_id', $journal_id)->select();
            $list[0]["periodical"] = $list2[0]["periodical"];
            return GlobalVariable::promptData($list[0]);
        } else {
            return GlobalVariable::promptErrorByJSON("错误", 400, "未找到该文章，请输入正确文章ID!");
        }
    }

    /**
     * 获得乱序随机十篇文章
     */

    public function getRandom()
    {
        $user = new User();
        $sql = "select * from `xwd_doc_thesis` order by rand() limit 10";
        $select = $user->query($sql);
        for ($i = 0; $i < 10; $i++) {
            $journal_id = $select[$i]["journal_id"];
            $list2 = Db::table('xwd_doc_journal')->where('journal_id', $journal_id)->select();
            $select[$i]["periodical"] = $list2[0]["periodical"];
        }
        return GlobalVariable::promptData($select);
    }

}